home *** CD-ROM | disk | FTP | other *** search
- Path: news.pi.net!news
- From: Marc Lucassen <lucassen@pi.net>
- Newsgroups: comp.lang.c++
- Subject: Re: how to delete data in file? help
- Date: Mon, 04 Mar 1996 21:34:43 -0800
- Organization: prive
- Message-ID: <313BD273.162B@pi.net>
- References: <4helpk$50c@lantana.singnet.com.sg>
- NNTP-Posting-Host: ams82.pi.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0b3 (Win16; I)
-
- Mikhail Choo W.M. wrote:
- >
- > HI there,
- > I know this may seem like a real stupid question, but I had to ask. If say
- > for example I needed to delete a string of data form a file, how do I go about
- > doing it. I can't just write over the data to delete, because the result would
- > be a file of the same length with white space chracters. So how does one delete
- > the data in such a way that once the data segment is deleted, the rest of the
- > data would neatly pack themselves over the deleted area to ensure a release of
- > space. I know one way to solve the problem, but it seems very long-winded. The
- > method involves reading all the data in the file to memory, deleteing the
- > unwanted area, and the re-write the data back to clean file. I am currently
- > using Borland C++ 4.5, and I can't find any function that does the job. OK OK,
- > to summerise, the problem is that I can't seem to find a way to directly delete
- > a data segment form a file, without reading into memory first. So any ideas, and
- > help would be greatly appreciated. Thanks in advance .
- > --------------------------------------------------------
- > Yours, Mikhail Choo W. M.
- > Carpedium!
- > E-Mail: mikhail@singnet.com.sg sieze the day...
- > s7700017@singnet.com.sg
- > --------------------------------------------------------
-
- There are a two possible ways of deleting data.
- 1. The strings all have the same size, you have to make a record with a
- string field of that size and a pointer field to the next record. You can
- insert a new string. You have to order them or read them directly from the
- file. This method can be done when you are making a database and is
- difficult.
- 2. Reading a byte (or string) from the old file and writing it to a new file
- without te deleted data. This is easier and better then reading the whole
- file at once.
- After this you copy the new file over the old file and delete the temporary
- file.
-
- The second method is the normal method for sequentialy readed files, used by
- professional programmer.
-